/*
 * @Author: szx
 * @Date: 2021-11-09 14:12:45
 * @LastEditTime: 2021-11-09 14:41:48
 * @Description:
 * @FilePath: \leetcode\100-199\153\153.cpp
 */
#include <iostream>
#include <vector>
using namespace std;
// class Solution {
//    public:
//     int findMin(vector<int>& nums) {
//         int minNum = INT_MAX;
//         for (int& i : nums) {
//             minNum = min(i, minNum);
//         }
//         return minNum;
//     }
// };

class Solution {
   public:
    int findMin(vector<int>& nums) {
        int n = nums.size();
        int l = 0, r = n - 1;
        while (l < r) {
            int mid = (r + l) / 2;
            if (nums[mid] < nums[r]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return nums[l];
    }
};

int main() {
    Solution s;
    vector<int> v = {1, 2, 3, 4};
    cout << s.findMin(v) << endl;
    return 0;
}